package com.neusoft.bd.myflink.step05;

import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class RichFunctionExample {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
        final SingleOutputStreamOperator<String> map = env.fromElements(1, 2, 3, 4)
                .map(new RichMapFunction<Integer, String>() {
                    @Override
                    public void open(Configuration parameters) throws Exception {
                        super.open(parameters);
                        getRuntimeContext().getIndexOfThisSubtask();
                    }

                    @Override
                    public String map(Integer integer) throws Exception {
                        return null;
                    }

                    @Override
                    public void close() throws Exception {

                    }
                });

    }
}
